﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace HML
{
    /// <summary>
    /// DropDownListPlus清除按钮
    /// </summary>
    [TypeConverter(typeof(PropertyOrderConverter))]
    public class DropDownListPlusClearButton
    {
        #region 属性

        private bool visible = false;
        /// <summary>
        /// 是否显示清除按钮
        /// </summary>
        [Description("是否显示清除按钮")]
        [PropertyOrder(-200)]
        [DefaultValue(false)]
        public bool Visible
        {
            get { return this.visible; }
            set
            {
                if (this.visible == value)
                    return;

                this.visible = value;
                this.InitializeInvalidate();
            }
        }

        private Color backNormalColor = Color.FromArgb(153, 204, 204);
        /// <summary>
        /// 清除按钮背景色(正常)
        /// </summary>
        [Description("清除按钮背景色(正常)")]
        [PropertyOrder(-198)]
        [DefaultValue(typeof(Color), "153, 204, 204")]
        public Color BackNormalColor
        {
            get { return this.backNormalColor; }
            set
            {
                if (this.backNormalColor == value)
                    return;

                this.backNormalColor = value;
                this.Invalidate();
            }
        }

        private Color foreNormalColor = Color.White;
        /// <summary>
        /// 清除按钮前景色(正常)
        /// </summary>
        [Description("清除按钮前景色(正常)")]
        [PropertyOrder(-196)]
        [DefaultValue(typeof(Color), "White")]
        public Color ForeNormalColor
        {
            get { return this.foreNormalColor; }
            set
            {
                if (this.foreNormalColor == value)
                    return;

                this.foreNormalColor = value;
                this.Invalidate();
            }
        }

        private Color backEnterColor = Color.FromArgb(130, 178, 178);
        /// <summary>
        /// 清除按钮背景色(鼠标进入)
        /// </summary>
        [Description("清除按钮背景色(鼠标进入)")]
        [PropertyOrder(-194)]
        [DefaultValue(typeof(Color), "130, 178, 178")]
        public Color BackEnterColor
        {
            get { return this.backEnterColor; }
            set
            {
                if (this.backEnterColor == value)
                    return;

                this.backEnterColor = value;
                this.Invalidate();
            }
        }

        private Color foreEnterColor = Color.White;
        /// <summary>
        /// 清除按钮前景色(鼠标进入)
        /// </summary>
        [Description("清除按钮前景色(鼠标进入)")]
        [PropertyOrder(-192)]
        [DefaultValue(typeof(Color), "White")]
        public Color ForeEnterColor
        {
            get { return this.foreEnterColor; }
            set
            {
                if (this.foreEnterColor == value)
                    return;

                this.foreEnterColor = value;
                this.Invalidate();
            }
        }

        #endregion

        #region 字段

        private DropDownListPlus owner = null;

        #endregion

        public DropDownListPlusClearButton(DropDownListPlus owner)
        {
            this.owner = owner;
        }

        #region 私有方法

        /// <summary>
        /// 刷新控件
        /// </summary>
        public void Invalidate()
        {
            if (this.owner != null)
            {
                this.owner.Invalidate();
            }
        }

        /// <summary>
        /// 重新计算控件并刷新控件
        /// </summary>
        public void InitializeInvalidate()
        {
            if (this.owner != null)
            {
                this.owner.InitializeRectangle();
                this.owner.Invalidate();
            }
        }

        #endregion


    }

}
